<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LoginController extends Controller
{
    public function login(){
        return view('login');
    }
    public function store(Request $request){
        $data=$this->validate($request,[
            'email'=>'required|email',
            'password'=>'required|min:5',
        ]);
        if(\Auth::attempt($data)){
            session()->flash('success','登陆成功');
            return redirect()->route('home');
        }
        session()->flash('danger','邮箱或者密码错误');
        return back();
    }
    //退出登录
    public function logout(){
        \Auth::logout();
        session()->flash('success','退出成功');
        return redirect()->route('home');
    }
}
